import requests
from business.logger import logger

def do_requests(url,method:str,params=None,data=None):
    method = method.lower()
    if method == 'get':
        logger.debug(f'{url} {method} query_params:{params}')
        res = requests.get(url=url,params=params)
        logger.debug(f'{res.status_code} {res.json()} {res.elapsed.total_seconds()}s')
        return res
    elif method == 'post':
        logger.debug(f'{url} {method} data:{params}')
        res = requests.post(url=url,data=data)
        logger.debug(f'{res.status_code} {res.json()} {res.elapsed.total_seconds()}s')
        return res
    else:
        logger.error(f'{method}不是正确的http请求方法,请检查')

